package com.cloudkinto.enumType.order.outbound;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.cloudkinto.vo.common.CommonKvVo;

import java.util.ArrayList;
import java.util.Objects;

/**
 * @author long
 */
public enum OutboundSignServiceEnum implements IEnum<Integer> {

    /**
     *
     */
    one(650, "DIRECT", "直接签署"),
    two(750, "INDIRECT", "间接签署"),
    three(850, "ADULT", "成人签署");

    private final Integer code;

    private final String desc;

    private final String name;

    OutboundSignServiceEnum(Integer code, String desc, String name) {
        this.code = code;
        this.desc = desc;
        this.name = name;
    }

    @Override
    public Integer getValue() {
        return code;
    }

    public static Integer getCodeByDesc(String desc) {
        if (StrUtil.isEmpty(desc)) {
            return null;
        }
        for (OutboundSignServiceEnum inboundType : values()) {
            if (inboundType.desc.equals(desc)) {
                return inboundType.code;
            }
        }
        return null;
    }

    public static String getDescByVal(Integer val) {
        if (Objects.isNull(val)) {
            return null;
        }
        for (OutboundSignServiceEnum inboundType : values()) {
            if (inboundType.code.equals(val)) {
                return inboundType.desc;
            }
        }
        return null;
    }

    public static ArrayList<CommonKvVo> getOrderOriginList() {
        ArrayList<CommonKvVo> list = new ArrayList<>();
        for (OutboundSignServiceEnum inboundType : values()) {
            list.add(
                    CommonKvVo.builder()
                            .label(inboundType.desc)
                            .value(inboundType.getValue())
                            .build()
            );
        }
        return list;
    }

    public static Integer getCodeByName(String name) {
        if (StrUtil.isEmpty(name)) {
            return null;
        }
        for (OutboundSignServiceEnum inboundType : values()) {
            if (inboundType.name.equals(name)) {
                return inboundType.code;
            }
        }
        return null;
    }

    public static String getNameByVal(Integer val) {
        if (Objects.isNull(val)) {
            return null;
        }
        for (OutboundSignServiceEnum inboundType : values()) {
            if (inboundType.getValue().equals(val)) {
                return inboundType.name;
            }
        }
        return null;
    }
}
